package com.io.client;

import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.Scanner;

/**
 * Created by 41579 on 2016/12/20.
 */
public class IOClient {
    public static void main(String[] args) throws Exception {
        Socket s = new Socket();
//        s.setSendBufferSize(1);
//        s.setReceiveBufferSize(10);
        System.out.println(s.getSendBufferSize());
        SocketAddress sa = new InetSocketAddress("127.0.0.1", 1000);
        s.connect(sa, 3000);
        System.out.println("建立连接成功。。。");
//        Thread t = new Thread(new myThread(s));
//        t.start();
        Scanner sc = new Scanner(System.in);
//        while (true) {
//            while(sc.hasNext()){
//            while (true) {
//                String stmp = sc.next();
//                Thread.sleep(3000);
                String stmp = "1";
                s.getOutputStream().write(stmp.getBytes());
//                System.out.println("写完了。。。。。");
//            }
//        }
        s.getOutputStream().close();
        while(true){

        }
    }

    static class myThread implements Runnable {
        Socket s;

        public myThread(Socket s) {
            this.s = s;
        }

        public void run() {
            try {
                InputStream is = s.getInputStream();
                byte[] byteps = new byte[1024];
                while (is.read(byteps) > 0) {
                    System.out.println("收到服务器回复：" + new String(byteps));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
